<script type="text/javascript">
var categoryList = undefined;
var currVoteCateIndex = -1;
var canIds = [];

$(function() {
	$("#doVote").on("click", openVoteUI);
	//加载投票种类
	getCategoryList();
	
});

function openVoteUI() {
	if(categoryList && ++currVoteCateIndex < categoryList.length) {
		var voteDialog = $('<div/>').dialog({
			href : 'moduls/fun/voteUI.html',
			width : 860,
			height : $(window).height(),
			title : categoryList[currVoteCateIndex].name+'评选',
			closable : false,
			border : false,
			modal : true,
			buttons : [ {
				text : currVoteCateIndex + 1 == categoryList.length ? '完成' : '下一步',
				iconCls : 'icon-save',
				handler : function() {
					if(categoryList[currVoteCateIndex].amount > $('#right_s table tr').length - 1) {
						topRight('请投足票数！');
					}else {
						saveVoteData();
						openVoteUI();
						$(voteDialog).dialog('destroy');
					}
				}
			} , {
				text : '取消',
				iconCls : 'icon-remove',
				handler : function() {
					currVoteCateIndex = -1;
					canIds = [];
					$(this).closest('.window-body').dialog('destroy');
				}
			}]
		});
	}else {
		currVoteCateIndex = -1;
		canIds = [];
	}
}

function openInfoUI(canId) {
	var voteDialog = $('<div/>').dialog({
		href : 'moduls/candidateInfo.html',
		width : 900,
		height : $(window).height(),
		closable : false,
		noheader : true,
		border : false,
		modal : true,
		buttons : [{
			text : '关闭',
			iconCls : 'icon-remove',
			handler : function() {
				$(this).closest('.window-body').dialog('destroy');
			}
		}],
		onLoad : function() {
			candidateInfo_init(canId);
		}
	});
}

function getCategoryList() {
	$.getJSON("categoryAction!query.action", function(data){
		categoryList = data;
	});
}

function topRight(str){  
    $.messager.show({  
        title:'提示：',  
        msg:str,  
        showType:'show',  
        style:{  
            left:'',  
            right:0,  
            top:document.body.scrollTop+document.documentElement.scrollTop,  
            bottom:'',
            zIndex:9999
        }  
    });  
}

function saveVoteData() {
	$('#right_s table tr[canId]').each(function(i, d) {
		canIds.push($(d).attr('canId'));
	});
	if(currVoteCateIndex + 1 == categoryList.length) {
		$.post("candidateAction!doVote.action", { ids:canIds.join(",")}, function (data) {
			var r = $.parseJSON(data);
			$.messager.show({
				title : '提示',
				msg : r.msg
			});
		});
		canIds = [];
	}
}
</script>
<style type="text/css">
<!--
.wma {
	padding: 60px;
}
.STYLE2 {
	font-size: x-large;
	font-family: "宋体";
}
.rule {
	line-height: 28px;
}
#goIcon {
	height: 100px;
	width: 100px;
	margin: auto;
}
-->
</style>

<div class="wma">

<span class="STYLE2">评优评先投票规则：</span><br />
<br />
<p class="rule">
&nbsp;&nbsp;&nbsp;&nbsp;①、每个用户有且只能进行一次投票。<br />
&nbsp;&nbsp;&nbsp;&nbsp;②、必须对每个种类进行选举才算完成这次投票。<br />
&nbsp;&nbsp;&nbsp;&nbsp;③、每个种类所选的人数必须等于界面提示的数目。</p>
</div>
<div id="goIcon">
<input type="image" src="imgs/go.jpg" onclick="openVoteUI()" height="100" width="100">
</div>
